import 'package:flutter/material.dart';

class BaseDialog extends Dialog {
  late BuildContext? dialogContext;

  //点击背景是否能够退出
  final bool barrierDismissible;

  BaseDialog({super.key, this.barrierDismissible = true});

  @mustCallSuper
  @override
  Widget build(BuildContext context) {
    dialogContext = context;
    return Container();
  }

  T show<T extends BaseDialog>(BuildContext context) {
    showDialog(
        context: context,
        // 点击遮罩不关闭对话框
        barrierDismissible: false,
        builder: (context) {
          return this;
        });
    return this as T;
  }

  void finish() {
    if (dialogContext != null) {
      Navigator.pop(dialogContext!);
    }
  }
}
